/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *deleteDuplicates(ListNode *head) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		if (head == NULL || head->next == NULL) {
			return head;
		}

		ListNode* i = head;
		for (; i != NULL) {
			ListNode* j = i;
			while (j && j->val == i->val) {
				// delete the node
				j = j->next;
			}
			i->next = j;
			i = j;
		}
        return head;
    }
};